﻿using B.S.BasicData.ErrorCode;
using B.S.BasicData.Write.Application.Common.Leave;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Write.Controllers
{
    /// <summary>
    /// Api 控制器-写(请假审批)
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LeaveController : ControllerBase
    {
        private readonly IMediator mediator;

        public LeaveController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 新增请假申请
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> LeaveAdd(LeaveAddCommand command)
        { 
            return mediator.Send(command);
        }

        /// <summary>
        /// 审批方法
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> LeaveHandle(LeaveCommon request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 删除请假信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> LeaveDel(LeaveDelCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 修改请假信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> UpdateLeave(LeaveUpdateCommand request)
        {
            return mediator.Send(request);
        }



    }
}
